#region [file: PessoaDAL.cs, author: Lucas Bittencourt]
// File:    PessoaDAL.cs
// Author:  Lucas Bittencourt
// Created: sábado, 24 de dezembro de 2011 01:06:32
// Purpose: Defines dao implementation class for class Pessoa
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IPessoaDAL interface
   /// </summary>
   public class PessoaDAL : NHibernateDALBase,  IPessoaDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Pessoa
      /// </summary>     
      public List<Pessoa> GetPessoaList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Pessoa)));
      }
      
      /// <summary>
      /// Get the instances of Pessoa from index firstResult to index maxResult
      /// </summary>
      public List<Pessoa> GetPessoaList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Pessoa), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Pessoa according its primary key instance.
      /// </summary>
      public Pessoa Load(PessoaPK pessoaPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "PesIdPessoa" };
         object[] values = new object[] { pessoaPK.PesIdPessoa };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Pessoa), cs);
         return (((list != null) && (list.Count > 0)) ? (Pessoa)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Pessoa according its example instance.
      /// </summary>
      public List<Pessoa> QueryByExample(Pessoa pessoa)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Pessoa), pessoa));
      }

      /// <summary>
      /// Query the instances of Pessoa according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Pessoa> QueryByExample(Pessoa pessoa, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Pessoa), pessoa, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Pessoa
      /// </summary>
      public void Insert(Pessoa pessoaObject)
      {
         base.Save(pessoaObject);
      }
      
      /// <summary>
      /// Update the instances of Pessoa
      /// </summary>
      public void Update(Pessoa pessoaObject)
      {
         base.Update(pessoaObject);
      }
      
      /// <summary>
      /// Delete the instances of Pessoa
      /// </summary>
      public void Delete(Pessoa pessoaObject)
      {
         base.Delete(pessoaObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesNmPessoa
      /// </summary>
      public List<Pessoa> FindByPesNmPessoa(string pesNmPessoa) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesNmPessoa", pesNmPessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs));
      }
      
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesNmPessoa, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Pessoa> FindByPesNmPessoa(string pesNmPessoa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesNmPessoa", pesNmPessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesNuCpfCnpj
      /// </summary>
      public List<Pessoa> FindByPesNuCpfCnpj(string pesNuCpfCnpj) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesNuCpfCnpj", pesNuCpfCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs));
      }
      
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesNuCpfCnpj, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Pessoa> FindByPesNuCpfCnpj(string pesNuCpfCnpj, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesNuCpfCnpj", pesNuCpfCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesDtCadastro
      /// </summary>
      public List<Pessoa> FindByPesDtCadastro(DateTime pesDtCadastro) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesDtCadastro", pesDtCadastro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs));
      }
      
      /// <summary>
      /// Find the instances of Pessoa according to its attribute pesDtCadastro, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Pessoa> FindByPesDtCadastro(DateTime pesDtCadastro, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PesDtCadastro", pesDtCadastro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Pessoa> ConvertToGenericList(IList pessoas)
      {
         List<Pessoa> pessoaList = new List<Pessoa>();
         foreach (Pessoa pessoa in pessoas)
         {
             pessoaList.Add(pessoa);
         }
         return pessoaList;
      }      
   }
}